#pragma once

#include <k4a/k4a.h>
#include "Common.h"

class DepthSensor {
public:
	virtual int init() { return 0; }
	virtual int start() { return 0; }
	virtual int reset() { return 0; }
	virtual int update() { return 0; }
};

class KinectDepthSensor: public DepthSensor {
	const int32_t TIMEOUT_IN_MS = 2000;

	k4a_device_t device;
	k4a_device_configuration_t config;
	k4a_calibration_t calibration;
	k4a_transformation_t transformation;
	
	k4a_capture_t capture;

	// TODO: need a smarter method handling the images
	k4a_image_t colorImage;
	k4a_image_t depthImage;
	k4a_image_t rgbdImage;

	bool deviceOpened;
	bool cameraStarted;

	int colorWidth;
	int colorHeight;

	int openDevice();
	int configure();
	int startCamera();

	bool captureGot;
	bool colorImageValid;
	bool depthImageValid;
	bool rgbdImageValid;

	int releaseData();

public:
	KinectDepthSensor() {
		device = NULL;
		transformation = NULL;
		deviceOpened = false;
		cameraStarted = false;
		captureGot = false;

		colorWidth = colorHeight = 0;
		colorImageValid = depthImageValid = rgbdImageValid = false;
	}
	int init() override;
	int start() override;
	int update() override;
	int getColorFrame(uint8_t** bufferPtr, int* width, int* height);
	int getDepthFrame(uint8_t** bufferPtr, int* width, int* height);
	int reset() override;
};